from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-18 14:02:48.104799
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 18, Sep, 2022
Time: 14:02:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4540
Nobs: 783.000 HQIC: -50.7839
Log likelihood: 10053.3 FPE: 7.16682e-23
AIC: -50.9900 Det(Omega_mle): 6.39328e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299039 0.054001 5.538 0.000
L1.Burgenland 0.108638 0.035958 3.021 0.003
L1.Kärnten -0.106468 0.019123 -5.567 0.000
L1.Niederösterreich 0.207634 0.075212 2.761 0.006
L1.Oberösterreich 0.104941 0.072547 1.447 0.148
L1.Salzburg 0.252476 0.038414 6.572 0.000
L1.Steiermark 0.038237 0.050165 0.762 0.446
L1.Tirol 0.105882 0.040681 2.603 0.009
L1.Vorarlberg -0.059636 0.034999 -1.704 0.088
L1.Wien 0.053630 0.064709 0.829 0.407
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060179 0.112022 0.537 0.591
L1.Burgenland -0.034219 0.074593 -0.459 0.646
L1.Kärnten 0.047867 0.039670 1.207 0.228
L1.Niederösterreich -0.175568 0.156023 -1.125 0.260
L1.Oberösterreich 0.392218 0.150496 2.606 0.009
L1.Salzburg 0.288157 0.079688 3.616 0.000
L1.Steiermark 0.107104 0.104064 1.029 0.303
L1.Tirol 0.312816 0.084391 3.707 0.000
L1.Vorarlberg 0.026825 0.072604 0.369 0.712
L1.Wien -0.018498 0.134235 -0.138 0.890
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191176 0.027735 6.893 0.000
L1.Burgenland 0.089706 0.018468 4.857 0.000
L1.Kärnten -0.008374 0.009822 -0.853 0.394
L1.Niederösterreich 0.262685 0.038629 6.800 0.000
L1.Oberösterreich 0.128877 0.037260 3.459 0.001
L1.Salzburg 0.047160 0.019730 2.390 0.017
L1.Steiermark 0.018331 0.025765 0.711 0.477
L1.Tirol 0.093477 0.020894 4.474 0.000
L1.Vorarlberg 0.059060 0.017976 3.286 0.001
L1.Wien 0.118911 0.033234 3.578 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109682 0.028317 3.873 0.000
L1.Burgenland 0.044958 0.018856 2.384 0.017
L1.Kärnten -0.015513 0.010028 -1.547 0.122
L1.Niederösterreich 0.194232 0.039440 4.925 0.000
L1.Oberösterreich 0.290220 0.038043 7.629 0.000
L1.Salzburg 0.114396 0.020144 5.679 0.000
L1.Steiermark 0.102006 0.026306 3.878 0.000
L1.Tirol 0.113446 0.021333 5.318 0.000
L1.Vorarlberg 0.070028 0.018353 3.816 0.000
L1.Wien -0.023901 0.033932 -0.704 0.481
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132616 0.051346 2.583 0.010
L1.Burgenland -0.052279 0.034190 -1.529 0.126
L1.Kärnten -0.039901 0.018183 -2.194 0.028
L1.Niederösterreich 0.172137 0.071513 2.407 0.016
L1.Oberösterreich 0.135726 0.068980 1.968 0.049
L1.Salzburg 0.287791 0.036525 7.879 0.000
L1.Steiermark 0.035408 0.047698 0.742 0.458
L1.Tirol 0.161466 0.038681 4.174 0.000
L1.Vorarlberg 0.100912 0.033278 3.032 0.002
L1.Wien 0.068152 0.061527 1.108 0.268
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058621 0.040841 1.435 0.151
L1.Burgenland 0.038586 0.027195 1.419 0.156
L1.Kärnten 0.051115 0.014463 3.534 0.000
L1.Niederösterreich 0.222600 0.056882 3.913 0.000
L1.Oberösterreich 0.284180 0.054868 5.179 0.000
L1.Salzburg 0.049088 0.029053 1.690 0.091
L1.Steiermark -0.004121 0.037940 -0.109 0.914
L1.Tirol 0.147663 0.030767 4.799 0.000
L1.Vorarlberg 0.072709 0.026470 2.747 0.006
L1.Wien 0.080526 0.048939 1.645 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180891 0.048799 3.707 0.000
L1.Burgenland -0.006550 0.032494 -0.202 0.840
L1.Kärnten -0.061122 0.017281 -3.537 0.000
L1.Niederösterreich -0.083822 0.067967 -1.233 0.217
L1.Oberösterreich 0.193362 0.065559 2.949 0.003
L1.Salzburg 0.056919 0.034714 1.640 0.101
L1.Steiermark 0.232494 0.045332 5.129 0.000
L1.Tirol 0.493076 0.036763 13.412 0.000
L1.Vorarlberg 0.048555 0.031628 1.535 0.125
L1.Wien -0.051601 0.058475 -0.882 0.378
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165980 0.055996 2.964 0.003
L1.Burgenland -0.010205 0.037287 -0.274 0.784
L1.Kärnten 0.066877 0.019830 3.373 0.001
L1.Niederösterreich 0.202136 0.077990 2.592 0.010
L1.Oberösterreich -0.070115 0.075228 -0.932 0.351
L1.Salzburg 0.212204 0.039833 5.327 0.000
L1.Steiermark 0.117666 0.052018 2.262 0.024
L1.Tirol 0.072912 0.042184 1.728 0.084
L1.Vorarlberg 0.122757 0.036292 3.382 0.001
L1.Wien 0.121546 0.067099 1.811 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358309 0.032447 11.043 0.000
L1.Burgenland 0.006072 0.021606 0.281 0.779
L1.Kärnten -0.023406 0.011490 -2.037 0.042
L1.Niederösterreich 0.218100 0.045191 4.826 0.000
L1.Oberösterreich 0.183372 0.043590 4.207 0.000
L1.Salzburg 0.046115 0.023081 1.998 0.046
L1.Steiermark -0.016635 0.030142 -0.552 0.581
L1.Tirol 0.107029 0.024443 4.379 0.000
L1.Vorarlberg 0.073463 0.021029 3.493 0.000
L1.Wien 0.048794 0.038880 1.255 0.209
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041061 0.150720 0.191623 0.156206 0.125324 0.112848 0.066548 0.223392
Kärnten 0.041061 1.000000 -0.002965 0.130183 0.041810 0.095522 0.430572 -0.053160 0.101252
Niederösterreich 0.150720 -0.002965 1.000000 0.337515 0.152473 0.300058 0.108000 0.183487 0.324032
Oberösterreich 0.191623 0.130183 0.337515 1.000000 0.228422 0.332136 0.172305 0.168155 0.265563
Salzburg 0.156206 0.041810 0.152473 0.228422 1.000000 0.146990 0.124003 0.147717 0.133487
Steiermark 0.125324 0.095522 0.300058 0.332136 0.146990 1.000000 0.152816 0.139341 0.079294
Tirol 0.112848 0.430572 0.108000 0.172305 0.124003 0.152816 1.000000 0.113701 0.153333
Vorarlberg 0.066548 -0.053160 0.183487 0.168155 0.147717 0.139341 0.113701 1.000000 0.006001
Wien 0.223392 0.101252 0.324032 0.265563 0.133487 0.079294 0.153333 0.006001 1.000000